package com.apes.scm.masterdata.product.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * @ClassName MaterialUsage
 * @Description 耗材用量
 * @Author pengyb
 * @Date 2019/12/24 17:10
 * @Version 1.0
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = MaterialUsage.CONST_TABLE_NAME)
public class MaterialUsage extends Model {
    public static final String CONST_TABLE_NAME = "mas_material_usage";

    @Id
    @Column(name = "id", length = 10)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "耗材用量", padding = 10)
    @Comment("耗材用量编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "category_id", referencedColumnName = "id")
    @Comment("配件名称")
    private Category category;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_uom_id", referencedColumnName = "id", nullable = false)
    @Comment("计量单位")
    private ProductUom uom;

    @Column(name = "dosage", nullable = false, columnDefinition = "NUMBER(16,2) default 0")
    @Comment("耗材标准用量")
    private double dosage = 0;

    @Column(name = "wave_ratio", nullable = false, columnDefinition = "NUMBER(16,2) default 0")
    @Comment("波动值")
    private double waveRatio = 0;
}
